package ru.ee.objects;

import ru.ee.MainScreen;
import android.view.MotionEvent;
import framework.GameConfig;
import framework.GameScreen;
import framework.graphics.Presentation;
import framework.managers.SoundManager;
import framework.managers.SystemInfoManager;
import framework.objects.ui.UI;
import framework.objects.ui.UIElement;

public class StringBtn extends UIElement {

	private float r;
	private String soundName;
	private Presentation passivePresentation;
	private Presentation activePresentation;
	
	public StringBtn(GameScreen screen, UI ui, float x0, float y0, 
			Presentation passivePresentation, 
			Presentation activePresentation,
			String soundName) {
		super(screen, ui, x0, y0);
		this.passivePresentation = passivePresentation;
		this.activePresentation = activePresentation;
		this.presentation = passivePresentation;
		initSize();
		this.r = presentation.getHeight() / 2 * 1.3f;
		this.soundName = soundName;
	}

	@Override
	public void handle(MotionEvent event) {
		float touchX = event.getX() / SystemInfoManager.getScaleX();
		float touchY = GameConfig.BASE_HEIGHT - event.getY() / SystemInfoManager.getScaleY();
//		Log.e("tuner", "x=" + touchX + " y=" + touchY);
		float action = event.getAction();
		if ((x - touchX)*(x - touchX) + (y - touchY)*(y - touchY) <= r * r) {
			if (action == MotionEvent.ACTION_DOWN) {
				playSound();
				((MainScreen)screen).setCurrentBtn(this);
				((MainScreen)screen).setCurrentLineY(y);
			}
		}
	}

	@Override
	protected void initPresentation() {
		// TODO Auto-generated method stub
		
	}

	public void playSound() {
		SoundManager.play(soundName);
	}
	
	public void activate() {
		presentation = activePresentation;
	}
	
	public void disactivate() {
		presentation = passivePresentation;
	}

}
